package com.swkl.yuan.agvtask.task;

import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
import com.swkl.yuan.agvtask.entity.AllConfig;
import lombok.SneakyThrows;

import javax.annotation.Resource;

/**
 * @Author Alkin
 * @Date 2023/3/7 12:32
 * @Version 1.0
 */
public class SendToPlc {


    /**
     * 出错反馈到plc
     * @param connector 链接
     */
    @SneakyThrows
    public static void  sendErrorSig(S7PLC connector){
        S7PLCUtil.writeInt16(connector, AllConfig.errorOffset,WORD_FOR_TRUE);
    }


    /**
     * 完成信号
     * @param connector 链接
     * @param finishOffset offset
     */
    @SneakyThrows
    public static void sendFinishSig( S7PLC connector,String finishOffset){
        S7PLCUtil.writeInt16(connector,finishOffset,WORD_FOR_TRUE);

    }

    /**
     * 心跳
     * @param connector 链接
     * @param heartbeatOffset offset
     */
    public static void heartbeat(S7PLC connector,String heartbeatOffset){
        connector.writeInt16(S7PLCUtil.getOffset(heartbeatOffset),WORD_FOR_FALSE);

    }

    /**
     * 重置触发信号
     * @param connector 链接
     * @param finishOffset offset
     */
    @SneakyThrows
    public static void sendResetSig(S7PLC connector,String finishOffset){
        S7PLCUtil.writeInt16(connector,finishOffset,WORD_FOR_FALSE);
    }


    public static final short WORD_FOR_TRUE =  1;
    public static final short  WORD_FOR_FALSE =  0;


}
